﻿using RecruitmentAgency.Models.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Web.Mvc;
using RecruitmentAgency.Models.DataTypes;

namespace RecruitmentAgency.Tests.Models.Validation
{
    /// <summary>
    ///This is a test class for AccountValidatorTest and is intended
    ///to contain all AccountValidatorTest Unit Tests
    ///</summary>
    [TestClass]
    public class AccountValidatorTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        private const string selectMessage = "Please select an option from the list";
        private ModelStateDictionary modelState;
        private AccountValidator target;
        private const int passwordLenght = 6;


        /// <summary>
        ///Initialises test members
        ///</summary>
        [TestInitialize]
        public void Initialize()
        {
            modelState = new ModelStateDictionary();
            target = new AccountValidator(modelState, selectMessage, passwordLenght);
        }

        /// <summary>
        ///A test for ValidateRegistrationJobProvider
        ///</summary>        
        [TestMethod]
        public void ValidateRegistrationJobProviderTest()
        {
            //expected to pass
            AccountValidator accountValidator = new AccountValidator(modelState, selectMessage, passwordLenght);
            const bool expected = true;
            bool actual = accountValidator.ValidateRegistrationJobProvider(new RegisterJobProvider
            {
                AddressLine1 = "AddressLine1",
                AddressLine2 = "AddressLine2",
                CompanyName = "CompanyName",
                JobProviderConfirmPassword = "Password",
                Email = "email@email.com",
                FirstName = "FirstName",
                LastName = "LastName",
                JobProviderPassword = "Password",
                PostCode = "Postcode",
                RegistrationNumber = "12321423423423",
                Title = "Mr",
                Town = "Town",
                JobProviderUserName = "Username",
                WebsiteUrl = "www.websiteurl.com"
            });
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidateRegistration
        ///</summary>       
        [TestMethod]
        public void ValidateRegistrationTest()
        {
            //Expected to fail
            AccountValidator accountValidator = new AccountValidator(modelState, selectMessage, passwordLenght);
            const bool expected = true;
            bool actual = accountValidator.ValidateRegistration(new Register
            {
                RegisterConfirmPassword = "Passord",
                PersonalEmail = "email@email.com",
                RegisterFirstName = "FirstName",
                RegisterLastName = "LastName",
                RegisterPassword = "Password",
                RegisterTitle = "Mr",
                RegisterUserName = "Username"
            });
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for ValidateLogOn
        ///</summary>
        [TestMethod]
        public void ValidateLogOnTest()
        {
            //expected to pass
            AccountValidator accountValidator = new AccountValidator(modelState, selectMessage, passwordLenght);
            Login login = new Login { UserName = "giga", Password = "giuseppe" };
            const bool expected = true;
            bool actual = accountValidator.ValidateLogOn(login);
            Assert.AreEqual(expected, actual);
        }
    }
}